
ifeq (,$(CC))
	CC=gcc -m32 
endif

ifeq (,$(AR))
	AR=ar
endif

ifneq (,$(COMPILE_PREFIX))
	CC:=$(COMPILE_PREFIX)gcc
	AR:=$(COMPILE_PREFIX)ar
endif

CFLAGS = -Wall -Wl,-Map,mapfile
#DEBUG = y

ifeq ($(DEBUG), y)
	CFLAGS += -g
else
	CFLAGS += -O3
endif

PWD=$(shell pwd)
SUBDIRS := src/module src/common  src/common/ini 


LDFLAGS = -L$(PWD)/lib -lpthread -lm



INCLUDES  =  -I$(PWD)/inc 
INCLUDES += -I$(PWD)/lib/include/opus
INCLUDES += -I$(PWD)/lib/include/keros
CFLAGS += ${INCLUDES}

SRC = $(wildcard src/common/*.c) \
	  $(wildcard src/*.c) \
	  $(wildcard src/module/*.c) \
	  $(wildcard extern/ini/*.c) 
   
OBJ = $(patsubst %.c,%.o,${SRC})

export CC  CFLAGS LDFLAGS INCLUDES

TARGET = libsn_script.a

MAKE = make

all: $(TARGET)

test: $(OBJ) test/main.o
	$(CC) $(CFLAGS) $^ -o script $(LDFLAGS) 


$(TARGET): $(OBJ)
	$(AR) -rc $@ $^

%.o:%.c
	$(CC) $(CFLAG) $(INCLUDES) -o $@ -c $<

clean:
	@rm -rf $(OBJ)
	rm  *.o $(TARGET) -f
	rm -rf script
	rm -rf test/main.o


.PHONY: all clean test
